package com.example.administrator.capital.base;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import android.support.annotation.Nullable;
import android.view.View;

import com.example.administrator.capital.utils.AppManager;
import com.lzy.okgo.OkGo;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import fragmentation.SupportActivity;

/**
 * Created by zzw on 2018/1/30 0030.
 *
 */
public abstract class BaseActivity extends SupportActivity implements View.OnClickListener{
    public Context mContext;
    private Unbinder mBind;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        doBeforeSetContentView();
        setContentView(getLayoutId());
        if (getSupportActionBar() != null) {//隐藏titleBar
            getSupportActionBar().hide();
        }
        mContext = this;
        mBind= ButterKnife.bind(this);

        this.initView();
        this.setListener();
        this.setData();
    }
    public abstract int getLayoutId();
    public abstract void initView();
    public abstract void setListener();
    public abstract void setData();
    /**
     * 设置layout前配置
     */
    private void doBeforeSetContentView() {
//         把actvity放到application栈中管理
        AppManager.getAppManager().addActivity(this);
        // 设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }


    /**
     * @param activity : 将要被显示的Activity
     * @param data     ： extraData
     */
    public void showActivity(Class<? extends BaseActivity> activity, Bundle data) {
        Intent intent = new Intent(this, activity);
        if (data != null) {
            intent.putExtras(data);
        }
        startActivity(intent);

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        mBind.unbind();
    }
}
